<template>
 <tr >
          <td>{{arr.id}}</td>
          <td>{{arr.name}}</td>
          <td>{{arr.date | dataFormat}}</td>
          <td>
            <button @click="del(arr.id)" :disable="disable">删除</button>
            <button @click="edit(arr.name,arr.id)">编辑</button>
          </td>
        </tr>
</template>

<script>
import axios from 'axios'
axios.defaults.baseURL = 'http://liufusong.top:4000/'
export default {
  props: {
    arr: {
      type: Object,
      required: true
    },
    getall: {
      type: Function,
      required: true
    },
    list: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      disable: false
    }
  },

  created () {

  },
  methods: {
    async del (id) {
      if (this.list.length === 1) {
        this.disable = true
      } else {
        this.disable = false
        try {
          await axios({
            url: 'books/' + id,
            method: 'delete'
          })
          this.getall()
        } catch (error) {
          alert('出错了')
        }
      }
    },
    async  edit (name, id) {
      this.$emit('edit', name)
      try {
        const res = await axios({
          url: 'books/' + id
        })
        console.log(res)
      } catch (error) {
        alert('出错了')
      }
    }
  }
}
</script>

<style scoped lang='less'>

</style>
